package top.maochang.hou.dao.impl;


import top.maochang.hou.dao.SecurityDao;
import top.maochang.hou.entity.SysUser;
import top.maochang.hou.utils.JDBCUtlis;

import java.util.ArrayList;
import java.util.List;

public class SecurityServiceImpl implements SecurityDao {

    @Override
    public SysUser findPasswordByLoginName(String loginName) {
        String sql = "select " +
                     "id           id," +
                     "username     userName," +
                     "password     passWord," +
                     "name         name," +
                     "phone        phone," +
                     "head_url     headUrl," +
                     "dept_id      deptId," +
                     "post_id      postId," +
                     "description  description," +
                     "status       status," +
                     "create_time  createTime," +
                     "update_time  updateTime," +
                     "is_deleted   isDeleted," +
                     "salt         salt " +
                     "from `sys_user` where userName=?";
        SysUser sysUser = JDBCUtlis.queryForOne(SysUser.class, sql, loginName);
        return sysUser;
    }

    @Override
    public List<String> findRoleByLoginName(String loginName) {
        List<String> list = new ArrayList<>();
        if ("admin".equals(loginName)){
            list.add("admin");
        }
        list.add("dev");
        return list;
    }

    @Override
    public List<String> findPermissionByLoginName(String loginName) {
        List<String> list = new ArrayList<>();
        if ("jay".equals(loginName)){
            list.add("order:add");
            list.add("order:list");
            list.add("order:del");
        }
        return list;
    }
}
